package com.example.demo.common;

import com.example.demo.config.Constant;
import com.example.demo.pojo.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-01-24
 * Time: 16:06
 */
public class SessionUtil {

    /**
     * 获得当前登录的用户信息
     * @param request
     * @return
     */
    public static User getUserInfo(HttpServletRequest request){
        HttpSession session = request.getSession(false);
        if( session != null && session.getAttribute(Constant.SESSION_USERINFO_KEY)!=null){
            return (User)session.getAttribute(Constant.SESSION_USERINFO_KEY);
        }
        return null;
    }
}
